package com.ruoyi.stock2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.DownTradedataSchedule;
import com.ruoyi.stock2.service.IDownTradedataScheduleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下载交易进度Controller
 * 
 * @author ruoyi
 * @date 2020-01-02
 */
@Controller
@RequestMapping("/stock2/SCHEDULE")
public class DownTradedataScheduleController extends BaseController
{
    private String prefix = "stock2/SCHEDULE";

    @Autowired
    private IDownTradedataScheduleService downTradedataScheduleService;

    @RequiresPermissions("stock2:SCHEDULE:view")
    @GetMapping()
    public String SCHEDULE()
    {
        return prefix + "/SCHEDULE";
    }

    /**
     * 查询下载交易进度列表
     */
    @RequiresPermissions("stock2:SCHEDULE:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DownTradedataSchedule downTradedataSchedule)
    {
        startPage();
        List<DownTradedataSchedule> list = downTradedataScheduleService.selectDownTradedataScheduleList(downTradedataSchedule);
        return getDataTable(list);
    }

    /**
     * 导出下载交易进度列表
     */
    @RequiresPermissions("stock2:SCHEDULE:export")
    @Log(title = "下载交易进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DownTradedataSchedule downTradedataSchedule)
    {
        List<DownTradedataSchedule> list = downTradedataScheduleService.selectDownTradedataScheduleList(downTradedataSchedule);
        ExcelUtil<DownTradedataSchedule> util = new ExcelUtil<DownTradedataSchedule>(DownTradedataSchedule.class);
        return util.exportExcel(list, "SCHEDULE");
    }

    /**
     * 新增下载交易进度
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存下载交易进度
     */
    @RequiresPermissions("stock2:SCHEDULE:add")
    @Log(title = "下载交易进度", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DownTradedataSchedule downTradedataSchedule)
    {
        return toAjax(downTradedataScheduleService.insertDownTradedataSchedule(downTradedataSchedule));
    }

    /**
     * 修改下载交易进度
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DownTradedataSchedule downTradedataSchedule = downTradedataScheduleService.selectDownTradedataScheduleById(id);
        mmap.put("downTradedataSchedule", downTradedataSchedule);
        return prefix + "/edit";
    }

    /**
     * 修改保存下载交易进度
     */
    @RequiresPermissions("stock2:SCHEDULE:edit")
    @Log(title = "下载交易进度", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DownTradedataSchedule downTradedataSchedule)
    {
        return toAjax(downTradedataScheduleService.updateDownTradedataSchedule(downTradedataSchedule));
    }

    /**
     * 删除下载交易进度
     */
    @RequiresPermissions("stock2:SCHEDULE:remove")
    @Log(title = "下载交易进度", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(downTradedataScheduleService.deleteDownTradedataScheduleByIds(ids));
    }
}
